#ifndef ENGINE_H
#define ENGINE_H

#include "Framework/Prerequisites.h"
#include "Framework/ITimer.h"
#include "Engine/FrameEvent.h"
#include "Graphics/IRenderWindow.h"
#include "Scene/SceneGraph.h"

namespace tyro
{
	namespace Engine
	{
		class Engine
		{
		public:
			Engine( );
			~Engine();
			
			
			void BeginRendering(void);
			bool RenderFrame(void);
			Graphics::IRenderWindow* Initialise( const String& windowTitle );

			void AddFrameListener(FrameListener* frameListener);

#pragma region SceneGraph
		public:
			Scene::SceneGraph* GetSceneGraph() const;
			Scene::SceneGraph* CreateSceneGraph();
		private:
			Scene::SceneGraph* sceneGraph;

#pragma endregion SceneGraph

#pragma region RenderEngine

		public:

			Graphics::IRenderEngine* GetRenderEngine(void);

		protected:
			
			bool UpdateRenderTargets( void );

			Graphics::IRenderEngine* renderEngine;

#pragma endregion RenderEngine

#pragma region FrameEventSystem

			bool StartFrame();
			bool StartFrame(FrameEvent& evt);
			bool QueueFrame( void );
			bool QueueFrame( FrameEvent& evt);
			bool EndFrame();
			bool EndFrame(FrameEvent& evt);
			void ClearFrameEventTimes(void);
			FLOAT_32 CalculateFrameTime( ULONG_32 currentTime, FrameEventTypes frameEventType );
			void InitialiseFrameEvent( FrameEventTypes frameEventType, FrameEvent& evt );
			

			typedef deque<ULONG_32>::type FrameEventTimesQueue;
			FrameEventTimesQueue frameEventTimes[FRAMEEVENT_COUNT];

			
			/** Set of registered frame listeners */
			set<FrameListener*>::type frameListeners;

#pragma endregion	FrameEventSystem

			// Holds if the engine is currently running
			bool running;

			Framework::ITimer* timer;
			
			


		};
	}
}


#endif
